package com.example.knowledgeget1.KnowtController;

import com.example.knowledgeget1.KnowtCommon.Service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/likes")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @PostMapping
    public ResponseEntity<?> addLike(@RequestBody Map<String, Long> json) {
        Long stuId = json.get("stuId");
        Long knowId = json.get("knowId");
        boolean success = likeService.addLike(stuId, knowId);
        if (success) {
            return new ResponseEntity<>("successfully", HttpStatus.CREATED);
        } else {
            return new ResponseEntity<>("Like already exists", HttpStatus.BAD_REQUEST);
        }
    }
}